/* 
 * File:   main.cpp
 * Author: mvdr
 *
 * Created on March 19, 2013, 2:55 PM
 */


#include <cstdlib>
#include <iostream>
#include <fstream>
#include "Model.h"
#include "Game.h"
#include "Utilities.h"
#include <cstring>
#include <ctime>
#include <sstream>


using namespace std;

/*
 * 
 */
int main(int argc, char** argv) {

    if (argc < 2)
    {
        cout << "Please specify the number of games\n";
        return 0;
    }
    
    set<string> arguments;
    
    for (int i = 2; i != argc; ++i)
        arguments.insert(argv[i]);
    
    bool magic = false;
    if (arguments.count("-m") == 1 || arguments.count("--magic") == 1)
        magic = true;
    
    bool verbose = false;
    
    bool magic = false;
    
    for (int i = 0; i != argc; ++i)
    	cout << argv[i] << ' ';
    
    cout << '\n'; 
    
    if (argc > 2)
		if (strcmp(argv[2], "--magic") == 0)
        	magic = true;
        
    if (magic)
    	cout << "Using magic\n";
	else
    	cout << "No magic\n";
    
    Game game(magic);
    
    if (magic)
    {
    	cout << "Using epistemagic\n";
        filename = "magic";
    }
    else
    	cout << "No epistemagic\n";
    
    time_t now = time(0);
    tm *ltm = localtime(&now);    
    
    stringstream ss;
    ss << "results/" << filename << '_' << prettyString(ltm->tm_mday, 2)
            << '-' << prettyString(ltm->tm_mon + 1, 2)
            << '_' << prettyString(ltm->tm_hour, 2)
            << ':' << prettyString(ltm->tm_min, 2) << ".csv";
    
    filename = ss.str();
    
    if (verbose)
        cout << "So you want verbosity, eh?\n";
    
    Game game(magic, verbose);
    int runs = min(atoi(argv[1]), game.nStates());
    
    for (int i = 0; i != runs; ++i)
    {        
        vector<size_t> result = game.run();
        writeResult(result, magic, filename);
    }
}



